const mobileReg = /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i;
const weixinReg = /MicroMessenger/i;
const alipayReg = /AliApp/i;

/**
 * 判断是否移动设备访问
 * @returns {boolean} true 移动设备  false pc设备
 */
export function isMobile() {
  return mobileReg.test(window.navigator.userAgent.toLowerCase());
}

/**
 * 判断是否微信内置浏览器环境
 * @returns {boolean} true 微信环境  false 浏览器
 */
export function isWeixin(agent) {
  return weixinReg.test(agent || navigator.userAgent.toLowerCase());
}

/**
 * 是否是支付宝
 * @param agent
 * @returns {boolean}
 */
export function isAlipay(agent) {
  return alipayReg.test(agent);
}

/**
 * 判断运行环境是安卓还是IOS
 * @returns  {boolean} true => 安卓 false => IOS
 */
export function isAndroid() {
  let u = navigator.userAgent;
  let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1 //android终端
  // let isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
  return isAndroid ? true : false
}
